{extend name="layout" /}
{block name="body"}
<div class="row">
  <div class="col-lg-12">
    <div class="card">
      <div class="card-body">
          <div class="form-group">
            <label for="old-password">旧密码</label>
            <input type="password" class="form-control" name="oldpwd" id="oldpassword" placeholder="输入账号的原登录密码">
          </div>
          <div class="form-group">
            <label for="new-password">新密码</label>
            <input type="password" class="form-control" name="newpwd" id="newpassword" placeholder="输入新的密码">
          </div>
          <div class="form-group">
            <label for="confirm-password">确认新密码</label>
            <input type="password" class="form-control" name="confirmpwd" id="confirmpassword" placeholder="请在输入一遍新的密码">
          </div>
          <button type="button" id="updatepassword" class="btn btn-primary">修改密码</button>
      </div>
    </div>
  </div>

</div>
{/block}
{block name="js"}
<script>
  $("#updatepassword").click(function () {
    var oldpassword = $("#oldpassword").val();
    var newpassword = $("#newpassword").val();
    var confirmpassword = $("#confirmpassword").val();
    var l = $('body').lyearloading({
      opacity: 0.2,
      spinnerSize: 'lg'
    });
    if (newpassword != confirmpassword) {
      l.destroy();
      notify.error("两次密码输入不一致");
      return false;
    }
    $.ajax({
      type: 'post',
      url: "{:url('admin/updatepassword')}",
      data: {
        "oldpassword": oldpassword,
        "newpassword": newpassword,
        "confirmpassword": confirmpassword
      },
      dataType: "json",
      success: function (data) {
        l.destroy();
        if (data.code == 1) {
          notify.success(data.msg,function(){
            location.reload();
          },1000);
        } else {
          notify.error(data.msg);
        }
      },
      error: function () {
        l.destroy();
        notify.error("生成失败");
      }
    })
  })
</script>
{/block}